package labuladong.双指针.两数之和;

public class twoNumsSum {
    public static void main(String[] args) {
        int[] arr = {2, 7, 11, 15};
        int target = 9;
        int[] solution = solution(arr, target);
        for (int i : solution) {
            System.out.println(i);
        }
    }

    public static int[] solution(int[] arr, int target) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int sum = arr[left] + arr[right];
            if (sum == target) {
                return new int[]{left+1, right+1};
            } else if(sum < target) {
                left++;
            }else if(sum > target) {
                right--;
            }
        }
        return new int[]{-1, -1};
    }
}
